<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>orderDetails</title>
</head>
<body>
	<h1>订单详情</h1>
	
	<table border="1">
		<tr>
			<td rowspan="2"> <img src="${order.merchant.logo }"></td>
			<td>商家名称</td>
			<td>商家电话</td>
			<td>订单时间</td>
			<td>商家地址</td>
			<td>商家评分</td>
			<td>
			<c:if test="${order.status==1 }">
				<c:if test="${order.receive==0 }">
					<span id="recieve">等待商家接单</span>
				</c:if>		
				<c:if test="${order.receive==1 }">
					<span id="recieve">商家已经接单</span>
				</c:if>		
				<c:if test="${order.receive==2 }">
					<span id="recieve">商家拒绝接单</span>
				</c:if>		
			</c:if>
			
			</td>		
		</tr>
		<tr>
			<td>${order.merchant.mName }</td>
			<td>${order.merchant.mTel }</td>
			<td>${order.dt }</td>
			<td>${order.merchant.address }</td>
			<td>${order.merchant.grade }</td>
		</tr>
	</table>
	<span id="oid" style="display:none">${order.oId }</span>	
	<table border="1">
		<c:forEach var="item" items="${order.orderItems }">
			<tr>
				<td rowspan="2"> <img src="${item.img }"></td>
				<td>菜品名</td>
				<td>数量</td>
				<td>单价</td>		
			</tr>
			<tr>
				<td>${item.dName }</td>
				<td>${item.num }</td>
				<td>${item.price }</td>
			</tr>
			<c:set value="${sum + item.price * item.num}" var="sum" />
		</c:forEach>
	</table>
	<span>总价：</span><span>${sum}</span>
	<span><a href="historicalOrders">返回</a></span>
</body>
<script type="text/javascript">

var oid=document.getElementById("oid");
var $=(function(){
	  function inner(){
		};
		inner.prototype.ajax=function(cf){
			
			var xhr;
			xhr=new XMLHttpRequest();
			xhr.onreadystatechange=function(){
				if(xhr.status==200){
					if(xhr.readyState==4){
						var d=JSON.parse(xhr.responseText);
						cf.success(d);
					}
				}
			};
			xhr.open(cf.method,cf.url);
			for(var t in cf.headers){
				xhr.setRequestHeader(t,cf.headers[t]);
			}
			xhr.send(JSON.stringify(cf.data));
		};
		return new inner();
	})();
function refresh(){		
		var i=oid.innerHTML;
		$.ajax({
			method : "GET",
			url : "refreshOrderDetails?oid=" + i,
			success : function(d) {
				getRecieveStatus(d);
			}
		});
	}
function getRecieveStatus(d){
	var span=document.getElementById("recieve");
	if(d==0){
		span.innerHTML="等待商家接单";
	}else if(d==1){
		span.innerHTML="商家已经接单";
	}else if(d==2){
		span.innerHTML="商家拒绝接单";					
	}
}
window.onload=function (){
	setInterval("refresh()", 5000);  	
}
</script>
</html>